<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>仓库管理</li>
    <li><a href="/erp1/rep/ware/allWare">仓库管理</a></li>
    <li>修改仓库</li>
  </ul>
</div>
<div class="formbody">
    <form action="/erp1/rep/ware/doupdate" method="post" id="updatefrom">

        <span th:text="${msg}" style="color: red"></span>
        <ul class="forminfo">
            <li>
                <label>仓库名称</label>
                <input type="hidden" name="id" th:value="${updateW.id}"/>
                <input type="hidden" name="pageno" th:value="${pagenoU}"/>
                <input name="cName" type="text" class="dfinput" th:value="${updateW.cName}" id="cName1"/>
                <i>必填，不能超过30个字符</i>
            </li>
            <li>
                <label>仓库地址</label>
                <input name="cAddress" type="text" class="dfinput" th:value="${updateW.cAddress}" id="cAddress1" />
                <i>必填，不能超过300个字符</i>
            </li>
            <li>
                <label>所属区域</label>
                <select class="dfselect" name="provinceId" onchange="getCity(this.value)" id="provinceId1">
                    <option value="0">请选择</option>
                    <option th:each="p : ${session.provinces}" th:value="${p.id}" th:text="${p.pName}" th:selected="${p.id==updateW.provinceId}"></option>
                </select>
                省
                <select class="dfselect" name="cityId" id="cityId1">
                    <option th:each="c : ${cities}" th:value="${c.id}" th:text="${c.cName}" th:selected="${updateW.cityId==c.id?true:false}"></option>
                </select>
                市
                <i>必选</i>
            </li>
            <li>
                <label>负责人</label>
                <select class="dfselect" name="usreId" id="usreId1">
                    <option value="0">请选择</option>
                    <option th:each="u : ${cwUsers}" th:value="${u.uId}" th:text="${u.uname}" th:selected="${u.uId==updateW.usreId}"></option>
                </select>
                <i>只能是财务部或仓库管理员职位</i>
            </li>
            <li>
                <label>联系方式</label>
                <input name="phone" type="text" class="dfinput" th:value="${updateW.phone}" id="phone1"/>
                <i>必填，不能超过30个字符</i>
            </li>
            <li>
                <label>描述</label>
                <textarea class="textinput" name="details" th:text="${updateW.details}"></textarea>
                <i>可选</i>
            </li>
            <li>
                <label>状态</label>
                <select class="dfselect" name="state">
                    <option th:each="m : ${maps}" th:value="${m.key}" th:text="${m.value}" th:selected="${updateW.state==m.key}?true:false"></option>
                </select>
                <i>必选</i>
            </li>
            <li>
                <label>创建人</label>
                <input type="text" th:value="${session.currUser.uname}" readonly="readonly" class="roinput" />
                <i>不能编辑</i>
            </li>
            <li>
                <label>创建时间</label>
                <input type="text" th:value="${#dates.format(updateW.creationTime,'yyyy-MM-dd HH:mm:ss')}" readonly="readonly" class="roinput" />
                <i>不能编辑</i>
            </li>
            <li>
                <label>&nbsp;</label>
                <input type="button" onclick="updateWarehouse()" class="btn" value="确定"/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" class="btn" value="返回" onclick="goPre()"/>
            </li>
        </ul>
    </form>
</div>
<script type="text/javascript">
    function getCity(num) {
        $.get("/erp1/ajaxCity", {"pid": num}, function (data) {
            $("select[name=cityId]").html("");
            var options = "<option value='0'>请选择</option>"
            $.each(data, function (i, e) {
                    options += "<option value=" + e.id + ">" + e.cname + "</option>"
            });
            $("select[name=cityId]").append(options);
        }, "json");
    }
    function goPre() {
        location.href="/erp1/rep/ware/allWare";
    }

    //简单验证
    $(function () {
        $("#cName1").blur(function () {
            warecName();
        });
        $("#cAddress1").blur(function () {
            warecAddress();
        });
        $("#provinceId1").blur(function () {
            wareprovinceId();
        });
        $("#cityId1").blur(function () {
            warecityId();
        });
        $("#usreId1").blur(function () {
            wareusreId();
        });
        $("#phone1").blur(function () {
            warephone();
        });
    });

    function warecName() {
        if($("#cName1").val()==""){
            return false;
        }else{
            return true;
        }
    }
    function warecAddress() {
        if($("#cAddress1").val()==""){
            return false;
        }else{
            return true;
        }
    }
    function wareprovinceId() {
        if($("#provinceId1").val()==""){
            return false;
        }else{
            return true;
        }
    }
    function warecityId() {
        if($("#cityId1").val()==""){
            return false;
        }else{
            return true;
        }
    }
    function wareusreId() {
        if($("#usreId1").val()==""){
            return false;
        }else{
            return true;
        }
    }
    function warephone() {
        if($("#phone1").val()==""){
            return false;
        }else{
            return true;
        }
    }
    function updateWarehouse() {
        if(warecName()&&warecAddress()&&wareprovinceId()&&warecityId()&&wareusreId()&&warephone()){
            $("#updatefrom").submit();
        }else{
            confirm("修改仓库失败，请检查是否漏填或格式错误！");
        }
    }
</script>
</body>
</html>
